package com.pattern.factory.simple;

/**
 * 简单工厂模式
 * @author LYao15
 */

/**
 * 1、创建抽象产品类
 */
abstract class Computer {
    /**
     * 产品的抽象方法，由具体的产品类去实现
     */
    public abstract void start();
}

/**
 * 2、创建具体产品类
 */
//联想电脑
class LenovoComputer extends Computer {
    @Override
    public void start() {
        System.out.println("联想电脑启动");
    }
}
//惠普电脑
class HpComputer extends Computer{
    @Override
    public void start() {
        System.out.println("惠普电脑启动");
    }
}
//华硕电脑
class AsusComputer extends Computer {
    @Override
    public void start() {
        System.out.println("华硕电脑启动");
    }
}

/**
 * 3、创建工厂类
 */
class ComputerFactory {

    public static Computer createComputer(String type){
        Computer mComputer=null;
        switch (type) {
            case "lenovo":
                mComputer=new LenovoComputer();
                break;
            case "hp":
                mComputer=new HpComputer();
                break;
            case "asus":
                mComputer=new AsusComputer();
                break;

        }
        return mComputer;
    }
}

public class SimpleFactoryTest {

    public static void main(String[]args){
        ComputerFactory.createComputer("hp").start();
    }
}

